package algorithm.leetcode;

import java.util.Comparator;
import java.util.Scanner;

public class test {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] arrs = new int[n + 5];
        for (int i = 1; i <= n; i++) {
            arrs[i] = scan.nextInt();
        }
        arrs[0] = n;
        System.out.println(sum(count(arrs)));
    }

    public static int[] merge(int[] arrs) {
        // 将多个的0合并为一个
        int[] res = new int[arrs[0] + 5];
        res[0] = 1;
        int index = 1;
        for (int i = 1; i <= arrs[0]; i++) {
            if (arrs[i] != 0) {
                res[index++] = arrs[i];
            } else if (arrs[i - 1] != 0) {
                res[index++] = arrs[i];
            }
        }
        res[0] = index;
        return res;
    }

    public static long sum(int[] nums) {
        int len = nums[0];
        long sum = 1;
        long mod = 998244353;
        for (int i = 1; i <= len; i++) {
            sum = sum * nums[i];
            sum = sum % mod;
        }
        return sum % mod;
    }

    public static int[] count(int[] arrs) {
        // 统计每个位置能有多少种数
        int[] num = new int[arrs[0] + 5];
        int len = arrs[0];
        for (int i = 1; i <= len; i++) {
            if (arrs[i] == 0) {
                num[i] = count(i, len, arrs);
            } else {
                num[i] = 1;
            }
        }
        num[0] = arrs[0];
        return num;
    }

    public static int count(int pos, int len, int[] arrs) {
        int min = 1;
        int max = 200;
        if (pos == 2) {
            // a[2]>=a[1]
            min = arrs[1];
        }
        if (pos == 1) {
            max = arrs[2];
        }
        if (pos == len - 1) {
            // a[n-1]>=a[n]
            min = Math.max(arrs[len], min);
        }
        if (pos == len) {
            max = Math.min(arrs[len - 1], max);
        }
        if (pos > 1 && pos < len) {
            // 普世规则
            max = Math.min(Math.max(arrs[pos - 1], arrs[pos + 1]), max);
        }
        return max - min + 1;
    }
    
}
